﻿using MLSMooc.BO;
using MLSMooc.DAO.Interface.Website;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using MLSMooc.Helper;
using Dapper;



namespace MLSMooc.DAO.Implement.Website
{
   public class WebsiteDAO : IWebsiteDAO
    {
        private static WebsiteDAO instance = new WebsiteDAO();
        private WebsiteDAO() { }

        public static WebsiteDAO Getinstance() => instance;

        private static readonly string queryField = "select * from Mooc_Course_Website where isDelete=0";

        public async Task<IEnumerable<WebsiteBO>> GetByIdWebsiteInfo(string id)
        {
            using (SqlConnection conn=new SqlConnection(SalesSysSqlHelper.connectionString))
            {
                StringBuilder sql = new StringBuilder(queryField);
                sql.Append($@" and Id in("+id+")");
                var res = await conn.QueryAsync<WebsiteBO>(sql.ToString());
                return res;
            }
        }
        public async Task<IEnumerable<WebsiteBO>> GetWebsiteAllList()
        {
            using (SqlConnection conn = new SqlConnection(SalesSysSqlHelper.connectionString))
            {
                StringBuilder sql = new StringBuilder(queryField);
                var res = await conn.QueryAsync<WebsiteBO>(sql.ToString());
                return res;
            }
        }
    }
}
